/*
 * SocketOption.h
 *
 *  Created on: 2012-12-7
 *      Author: yangentao@gmail.com
 */

#pragma once;

#include <WinSock2.h>

namespace yet {
//If the setsockopt function is called before the bind function, TCP/IP options will not be checked with TCP/IP until the bind occurs. In this case, the setsockopt function call will always succeed, but the bind function call can fail because of an early setsockopt failing
class SocketOption {
public:
	SocketOption(SOCKET sock);
	virtual ~SocketOption();
public:

	//SO_BROADCAST
	BOOL isBroadcastEnable();
	void setBroadcast(BOOL enable);

	//SO_LINGER
	LINGER getLinger();
	//when closesocket invoked
	void setLinger(BOOL on, short seconds = 5);

	//TCP_NODELAY
	void setTcpNoDelay(BOOL noDelay);
	BOOL isTcpNoDelay();


	//SO_SNDBUF
	int getSendBufferSize();
	void setSendBufferSize(int size);

	//SO_RCVBUF
	int getReceiveBufferSize();
	void setReceiveBufferSize(int size);

	//for udp,after bind
	//SO_MAX_MSG_SIZE
	int getMaxMsgSize();

//	SO_DEBUG
	BOOL isDebug();
	void setDebug(BOOL dbg);
//	SO_DONTROUTE
	BOOL isDontRoute();
	void setDontRoute(BOOL dontRoute);
//	SO_DONTLINGER
	BOOL isDontLinger();
	void setDontLinger(BOOL dontLinger);
//	SO_KEEPALIVE
	BOOL isKeepAlive();
	void setKeepAlive(BOOL keepAlive);

//	SO_REUSEADDR
	BOOL isReuseAddr();
	void setReuseAddr(BOOL reuse);

//	SO_OOBINLINE
	BOOL isOOBInline();
	void setOOBInline(BOOL inln);

//	SO_EXCLUSIVEADDRUSE
	BOOL isExclusiveAddrUse();
	void setExclusiveAddrUse(BOOL exclusive);

////	SO_UPDATE_ACCEPT_CONTEXT
//	SOCKET getUpdateAcceptContext();
//	void setUpdateAcceptContext(SOCKET listenSocket);

//	SO_CONDITIONAL_ACCEPT
	BOOL isConditionalAccept();
	void setConditionalAccept(BOOL condAccept);
public:
	void setSocketInt(int optname, int value);
	int getSocketInt(int optname);
	void setInt(int level, int optname, int value);
	int getInt(int level, int optname);
private:
	SOCKET sock;
};

} /* namespace yet */
